home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / tkern091.zip / SRC / TDEVICE.C < prev    next >
Text File  |  1994-03-05  |  2KB  |  111 lines

  1. /*
  2.  *  This file forms part of "TKERN" - "Troy's Kernel for Windows".
  3.  *
  4.  *  Copyright (C) 1994  Troy Rollo <troy@cbme.unsw.EDU.AU>
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <string.h>
  22. #include <errno.h>
  23. #include <sys/tdevice.h>
  24.  
  25. extern    int    nError;
  26.  
  27. #pragma argsused
  28. static    long
  29. invalid_seek(    int    id,
  30.         long    loc,
  31.         int    from)
  32. {
  33.     nError = EINVAL;
  34.     return -1;
  35. }
  36.  
  37. extern    int    window_open(    char const *,
  38.                 int,
  39.                 int);
  40. extern    int    window_close(    int);
  41. extern    int    window_read(    int,
  42.                 char *,
  43.                 int);
  44. extern    int    window_write(    int,
  45.                 char const *,
  46.                 int);
  47. extern    int    window_ioctl(    int,
  48.                 struct    tk_ioctl *);
  49.                 
  50.  
  51. extern    int    file_open(    char const *,
  52.                 int,
  53.                 int);
  54. extern    int    file_close(    int);
  55. extern    long    file_seek(    int,
  56.                 long,
  57.                 int);
  58. extern    int    file_read(    int,
  59.                 char *,
  60.                 int);
  61. extern    int    file_write(    int,
  62.                 char const *,
  63.                 int);
  64. extern    int    file_ioctl(    int,
  65.                 struct    tk_ioctl *);
  66.                 
  67.  
  68. struct    tdevice    dev_list[] =
  69. {
  70.     {
  71.     window_open,    invalid_seek,    window_read,    window_write,
  72.     window_close,    window_ioctl,    "window",    DF_TTY,    /* 00 */
  73.     },
  74.  
  75.     {
  76.     file_open,    file_seek,    file_read,    file_write,
  77.     file_close,    file_ioctl,    "file",        0    /* 01 */
  78.     }
  79. };
  80.  
  81. int    num_devs = sizeof(dev_list) / sizeof(dev_list[0]);
  82.  
  83.  
  84. int
  85. get_device_number(char const *pchDevice)
  86. {
  87.     int    i;
  88.     char    achDevice[256];
  89.     char    const *c;
  90.  
  91.     c = strchr(pchDevice, '/');
  92.     if (c)
  93.     {
  94.         if (c - pchDevice >= 256)
  95.             return -1;
  96.         strncpy(achDevice, pchDevice, c - pchDevice);
  97.         achDevice[c - pchDevice] = 0;
  98.     }
  99.     else
  100.     {
  101.         strcpy(achDevice, pchDevice);
  102.     }
  103.  
  104.     for (i = 0; i < num_devs; i++)
  105.     {
  106.         if (!strcmp(achDevice, dev_list[i].devname))
  107.             return i;
  108.     }
  109.     return 0;
  110. }
  111.